<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
	
export default {
  name: 'School',
  props: {
    msg: String
  },
  methods:{
	  demo(msgName,data){
		  console.log('有人订阅了hello消息,hello消息的回调执行了',data,this)
	  }
  },
  mounted() {
  	this.pubId = pubsub.subscribe('hello',this.demo);
  },
  beforeDestroy() {
  	pubsub.unsubscribe(this.pubId)
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	
</style>
